package com.caojm.mptools;

import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

public class MiningData {

    private static final Map<String, Integer> playerMiningStats = new HashMap<>();

    // 更新玩家的挖掘数据
    public static void addMiningData(String playerName) {
        playerMiningStats.put(playerName, playerMiningStats.getOrDefault(playerName, 0) + 1);
    }

    // 获取玩家的挖掘数据
    public static int getMiningData(String playerName) {
        return playerMiningStats.getOrDefault(playerName, 0);
    }

    // 获取挖掘数据前10的玩家
    public static Map<String, Integer> getTop10() {
        return playerMiningStats.entrySet()
                .stream()
                .sorted((entry1, entry2) -> entry2.getValue().compareTo(entry1.getValue()))  // 按值降序排序
                .limit(10)  // 只取前10
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    }
}
